package group.cs.purdue.edu;

import global.sgb.cs.purdue.edu.AttrType;
import global.sgb.cs.purdue.edu.Distance;
import global.sgb.cs.purdue.edu.InMemorySGB;
import global.sgb.cs.purdue.edu.L2distance;
import global.sgb.cs.purdue.edu.LinfinityDistance;
import global.sgb.cs.purdue.edu.Tuple;

import java.util.ArrayList;

public class ArrayListGroups implements Groups {

	ArrayList <Group>gs;
	
	static double EPS;
	private int count;
	private int DistanceMetric;
	
	public ArrayListGroups() {
		// TODO Auto-generated constructor stub
		this.gs=new ArrayList<Group>();
		count=0;
	}

	/**
	 * 
	 */
	public ArrayList intersection(Tuple t, int []Fileds)
	{
		int metric=this.getDistanceMetric();
		ArrayList <Group>tmp= new ArrayList<Group>();
		
		Distance d=null;
		
		if(metric==AttrType.L2)
		{
			d=new L2distance();
		}else
		{
			d=new LinfinityDistance();
		}
		
		for(Group g:this.gs)
		{
			Tuple center=g.getCenter();
			double distance=d.getDistance(metric, center, t, Fileds);
			
			//this is very importance point here
			if(distance<=2*this.EPS)
			{
				tmp.add(g);
			}
		}
		
		return tmp;
	
	}
	
	/**
	 * @param g
	 */
	public void addgroup(Group g)
	{
		this.gs.add(g);
		this.incrementCount();
	}
	
	/**
	 * @param g
	 */
	public void deletegroup(Group g)
	{
		this.gs.remove(g);
		
	}
	
	/**
	 * 
	 * @param gindex
	 * @param g
	 * @param t
	 */
	public void deletefromgroup(int gindex, Group g, Tuple t)
	{
	}
	
	/**
	 * @
	 */
	public void addTupleTogroup(int gindex, Group g, Tuple t)
	{
		
	}

	@Override
	public void outputgroups() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setEPS(double eps) {
		// TODO Auto-generated method stub
		this.EPS=eps;
		
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.count;
	}

	@Override
	public void incrementCount() {
		// TODO Auto-generated method stub
		this.count++;
		
	}

	@Override
	public void setDistanceMetric(int s) {
		// TODO Auto-generated method stub
		
		this.DistanceMetric=s;
		
	}

	@Override
	public int getDistanceMetric() {
		// TODO Auto-generated method stub
		return this.DistanceMetric;
	}
	
	public String toString()
	{
		StringBuffer s= new  StringBuffer();
		
		for(Group g:this.gs)
		{
			s.append(g.toString()+"\n");
		}
		
		return s.toString();
	}
}
